package net.lzzy.practices.web.handler;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
import sun.font.EAttribute;

import javax.servlet.http.HttpServletRequest;
/**
 *@author lzzy_gxy on 2022/5/5.
 *Description:
 */
@ControllerAdvice
public class PracticeExceptionHandler {
    @ExceptionHandler
    public ModelAndView handBusinessException(HttpServletRequest request,BusinessException e){
        String errInfo="业务异常："+e.getErrInfo();
        ModelAndView mv=new ModelAndView();
        mv.addObject("title",errInfo);
        mv.addObject("url",request.getRequestURI().toString());
        mv.addObject("exception",e);
        mv.setViewName("error/error");
        return mv;
    }
    @ExceptionHandler(Exception.class)
    public ModelAndView handBusinessException(HttpServletRequest request,Exception e){
        ModelAndView mv=new ModelAndView();
        mv.addObject("title","非业务异常");
        mv.addObject("url",request.getRequestURI().toString());
        mv.addObject("exception",e);
        mv.setViewName("error/error");
        return mv;
    }

}
